package com.gqj.meter.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.gqj.meter.domain.MdChkTask;
import com.gqj.meter.service.IMdChkTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gqj.common.annotation.Log;
import com.gqj.common.core.controller.BaseController;
import com.gqj.common.core.domain.AjaxResult;
import com.gqj.common.enums.BusinessType;
import com.gqj.meter.domain.MdChkTaskDetails;
import com.gqj.meter.service.IMdChkTaskDetailsService;
import com.gqj.common.utils.poi.ExcelUtil;
import com.gqj.common.core.page.TableDataInfo;

/**
 * 盘点任务详情Controller
 * 
 * @author lxq
 * @date lxq-02-10
 */
@Api(value="/meter/mdChkTaskDetails",description = "盘点任务详情")
@RestController
@RequestMapping("/meter/mdChkTaskDetails")
public class MdChkTaskDetailsController extends BaseController
{
    @Autowired
    private IMdChkTaskDetailsService mdChkTaskDetailsService;
    @Autowired
    private IMdChkTaskService mdChkTaskService;

    /**
     * 查询盘点任务详情列表
     */
    @ApiOperation("查询盘点任务详情列表")
    @PreAuthorize("@ss.hasPermi('meter:mdChkTaskDetails:list')")
    @GetMapping("/list")
    public TableDataInfo list(MdChkTaskDetails mdChkTaskDetails)
    {
        startPage();
        List<MdChkTaskDetails> list = mdChkTaskDetailsService.selectMdChkTaskDetailsList(mdChkTaskDetails);
        return getDataTable(list);
    }

    /**
     * 导出盘点任务详情列表
     */
    @ApiOperation("导出盘点任务详情列表")
    @PreAuthorize("@ss.hasPermi('meter:mdChkTaskDetails:export')")
    @Log(title = "盘点任务详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MdChkTaskDetails mdChkTaskDetails)
    {
        Long chkTaskId = mdChkTaskDetails.getChkTaskId();

        MdChkTask mdChkTask = mdChkTaskService.selectMdChkTaskByChkTaskId(chkTaskId);
        if(mdChkTask.getAssetsCategory().equals("01")){
            List<MdChkTaskDetails> list = mdChkTaskDetailsService.selectMdChkTaskDetailsListExcel(mdChkTaskDetails);
            ExcelUtil<MdChkTaskDetails> util = new ExcelUtil<MdChkTaskDetails>(MdChkTaskDetails.class);
            util.exportExcel(response, list, "盘点任务详情数据");
        }else {
            List<MdChkTaskDetails> list = mdChkTaskDetailsService.selectMdChkTaskDetailsList(mdChkTaskDetails);
            ExcelUtil<MdChkTaskDetails> util = new ExcelUtil<MdChkTaskDetails>(MdChkTaskDetails.class);
            util.hideColumn("voltCode", "currentCode", "wiringMode", "manufacturer");
            util.exportExcel(response, list, "盘点任务详情数据");
        }
    }

    /**
     * 获取盘点任务详情详细信息
     */
    @ApiOperation("获取盘点任务详情详细信息")
    @PreAuthorize("@ss.hasPermi('meter:mdChkTaskDetails:query')")
    @GetMapping(value = "/{taskDetailsId}")
    public AjaxResult getInfo(@PathVariable("taskDetailsId") Long taskDetailsId)
    {
        return success(mdChkTaskDetailsService.selectMdChkTaskDetailsByTaskDetailsId(taskDetailsId));
    }

    /**
     * 新增盘点任务详情
     */
    @ApiOperation("新增盘点任务详情")
    @PreAuthorize("@ss.hasPermi('meter:mdChkTaskDetails:add')")
    @Log(title = "盘点任务详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MdChkTaskDetails mdChkTaskDetails)
    {
        return toAjax(mdChkTaskDetailsService.insertMdChkTaskDetails(mdChkTaskDetails));
    }

    /**
     * 修改盘点任务详情
     */
    @ApiOperation("修改盘点任务详情")
    @PreAuthorize("@ss.hasPermi('meter:mdChkTaskDetails:edit')")
    @Log(title = "盘点任务详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MdChkTaskDetails mdChkTaskDetails)
    {
        return toAjax(mdChkTaskDetailsService.updateMdChkTaskDetails(mdChkTaskDetails));
    }

    /**
     * 删除盘点任务详情
     */
    @ApiOperation("删除盘点任务详情")
    @PreAuthorize("@ss.hasPermi('meter:mdChkTaskDetails:remove')")
    @Log(title = "盘点任务详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskDetailsIds}")
    public AjaxResult remove(@PathVariable Long[] taskDetailsIds)
    {
        return toAjax(mdChkTaskDetailsService.deleteMdChkTaskDetailsByTaskDetailsIds(taskDetailsIds));
    }
}
